public class Product {
    private String id;
    private String name;
    private double price;

    // 构造方法、getter 和 setter 等
    public Product() {}

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}

public class ProductModel {

    // 模拟结算计算
    public double calculateTotalPrice(List<Product> products) {
        double total = 0;
        for (Product p : products) {
            total += p.getPrice();
        }
        return total;
    }
}

public interface ProductView {

    // 结算相关
    void onSettlementSuccess(double totalPrice);

    void onSettlementFailure(String error);
}

public class ProductPresenter {

    private ProductModel productModel;
    private ProductView productView;

    public ProductPresenter(ProductModel productModel, ProductView productView) {
        this.productModel = productModel;
        this.productView = productView;
    }

    public void settle(List<Product> products) {
        try {
            double totalPrice = productModel.calculateTotalPrice(products);
            productView.onSettlementSuccess(totalPrice);
        } catch (Exception e) {
            productView.onSettlementFailure("结算出错");
        }
    }
}

public class MainActivity extends AppCompatActivity implements ProductView {

    private ProductPresenter productPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ProductModel productModel = new ProductModel();
        productPresenter = new ProductPresenter(productModel, this);
    }

    public void onSettlementButtonClicked(View view) {
        List<Product> products = new ArrayList<>(); // 模拟已选产品列表
        productPresenter.settle(products);
    }

    @Override
    public void onSettlementSuccess(double totalPrice) {
        Toast.makeText(this, "结算总价: " + totalPrice, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onSettlementFailure(String error) {
        Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
    }
}